package com.zx._01_基础._011_集合;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import org.junit.Test;

public class CollectionTest {

    //1.同步控制
    @Test
    public void test01() {
        Collection<Object> collection = Collections.synchronizedCollection(new ArrayList<>());

        List<Object> list = Collections.synchronizedList(new ArrayList<>());

        Set<Object> set = Collections.synchronizedSet(new HashSet<>());

        Map<Object, Object> map = Collections.synchronizedMap(new HashMap<>());

        SortedMap<Object, Object> sortedMap = Collections.synchronizedSortedMap(new TreeMap<>());

        SortedSet<Object> sortedSet = Collections.synchronizedSortedSet(new TreeSet<>());
    }

    //2.设置不可变集合
    @Test
    public void test02() {
        //1.返回一个空的、不可变的集合对象
        List<Object> list = Collections.emptyList();
        Iterator<Object> iterator = Collections.emptyIterator();
        Map<Object, Object> map = Collections.emptyMap();
        Set<Object> set = Collections.emptySet();

        //2.返回一个只有一个元素的集合，且不可变
        Collections.singletonList(new Object());
        Collections.singletonMap("key", "value");

        //3.返回指定集合的不可变试图。
        Collection<Object> objects = Collections.unmodifiableCollection(new ArrayList<>());
    }

}
